#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	int i,i2;
	int t=0;
	cin>>N;
	int len[1010][3];
	int sum[1010];
	for (i=1;i<=N;i++)
	{
		cin>>len[i][1]>>len[i][2]>>len[i][3];
		sum[i] = len[i][1] + len[i][3] + len[i][2];
	}
	for (i=1;i<=N;i++)
	{
		for (i2=i+1;i2<=N;i2++)
		{
			if (abs(len[i][1]-len[i2][1])<=5 && abs(len[i][2]-len[i2][2])<=5 && abs(len[i][3]-len[i2][3])<=5 && abs(sum[i]-sum[i2])<=10) t = t + 1;
		}
	}
	cout<<t<<endl;
	return 0;
}
